<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title></title>
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
	<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
	<script th:src="@{/static/main.js}"></script>

	<style>
		.container {
			padding-top: 10px;
		}
		.cover {
			display: inline-block;
			width: 30px;
			height: 30px;
			position: absolute;
			right: 160px;
			top: 9px;
			z-index: 100;
			cursor: pointer;
		}
	</style>
</head>
<body>

<div class="container-fluid" id="app" style="margin-top: 5px;margin-bottom: 100px">

	<div class="container" v-if="stores.length<=0">
		<h3 style="text-align: center">很可惜，空空如也~</h3>
	</div>

	<div class="container" v-if="stores.length>0">

		<div class="row">
			<div class="col-md-12">
				<p style="background-color: #458b74 ; color: white; font-size: 30px; padding-left: 10px; border-radius: 4px">所有餐店</p>
			</div>
		</div>

		<div class="row">
			<div class="col-sm-6 col-md-12" v-for="store in stores">
				<div class="thumbnail" style="box-shadow: 5px 5px 3px 0px #CCCCCC">
					<img v-if="!store.storeImg" src="/static/109951166155909486.jpg" alt="..." class="col-sm-2 col-md-2">
					<img v-if="store.storeImg" :src="store.storeImg" alt="..." class="col-sm-2 col-md-2">
					<div class="caption text-left">
						<p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">店铺名:<span v-text="store.storeName">storeName</span></p>
						<p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">介绍:<span v-text="store.detail">detail</span></p>
						<p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">经营类型:<span v-text="store.typeName">typeName</span></p>
						<p class="text-muted" style="font-size: larger;font-weight: bold;font-family: 'Lora',serif">地址:<span v-text="store.address">address</span></p>
						<p style="padding-left: 900px;position: relative;bottom: 70px;">
							<a class="btn btn-success" :href="'/store/toStoreMenu?storeId='+store.id">详情菜单</a> &nbsp;&nbsp;&nbsp;
						</p>
					</div>
				</div>
			</div>
		</div>


		<div class="row">
			<div class="col-md-offset-5 col-lg-offset-4col-xl-offset-5">
				<ul class="pagination justify-content-center">
					<li><a href="javascript:void(0)" @click.prevent="go(currentPage-1)">&laquo;</a></li>
					<li><a href="javascript:void(0)" v-for="n in totalPages" v-text="n" @click.prevent="go(n)">n</a>
					</li>
					<li><a href="javascript:void(0)" @click.prevent="go(currentPage+1)">&raquo;</a></li>
				</ul>
			</div>
		</div>

	</div>


</div>

<script>

	console.log(".........userapp...........")

	let userapp = new Vue({
		el: "#app"
		,
		data: {
			stores: [],
			storeTypes: [],

			currentPage: 1,
			pageSize: 2,
			total: 0,
			totalPages: 0


		}
		,
		methods: {
			initAllStores() {
				let _this = this;
				let params = {
					currentPage: _this.currentPage,
					pageSize: _this.pageSize
				}
				console.log(params);
				$.post("/store/select", params, function (data) {

					_this.stores = data.records;
					_this.currentPage = data.current;
					_this.pageSize = data.size;
					//数据总量
					_this.total = data.total;
					//总页数
					_this.totalPages = data.pages;
				})
			}
			,
			initStoreTypes() {
				let _this = this;
				$.get("/storeType/all",function (data) {
					_this.storeTypes = data;
				})
			}
			,
			go(pageNum) {
				//小于1 或者 大于total 或者 仍获取当前页数据 直接返回
				if (pageNum < 1 || pageNum > this.totalPages || pageNum == this.currentPage) {
					console.log(pageNum + " 无效页码值")
					return;
				}

				this.currentPage = pageNum;
				this.initAllStores();
			}
			,
			toSearch() {
				//初始化页数
				this.currentPage = 1;
				this.initAllStores();
			}
		}
		,
		created() {
			this.initAllStores();
			this.initStoreTypes();
		}

	});


</script>

</body>
</html>

